//
//  YTFFooterView.swift
//  sinaWeibo
//
//  Created by pro on 16/3/2.
//  Copyright © 2016年 pro. All rights reserved.
//

import UIKit

class YTFFooterView: UIView {
    
    //定义一个属性
    var footerViewModel: YTFStatusViewModel?{
        didSet{
            //转发
            repostButton.setTitle(footerViewModel?.repostString, forState: UIControlState.Normal)
            //评论
            commentsButton.setTitle(footerViewModel?.commentString, forState: UIControlState.Normal)
            //点赞
            goodButton.setTitle(footerViewModel?.goodString, forState: UIControlState.Normal)
            
        }
    }

    //自定义FooterView
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    //添加控件和约束
    private func setupUI(){
        
        //添加子控件
        addSubview(repostButton)
        addSubview(commentsButton)
        addSubview(goodButton)
        let line1 = getLine()
        let line2 = getLine()
        addSubview(line1)
        addSubview(line2)
        
        
        //添加约束
        repostButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            
            //关键设置宽度
            make.width.equalTo(commentsButton.snp_width)
        }
        
        
        commentsButton.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(repostButton.snp_right)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            make.right.equalTo(goodButton.snp_left)
            
    
        }
        
        goodButton.snp_makeConstraints { (make) -> Void in
            make.right.equalTo(self.snp_right)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            //关键设置宽度
            make.width.equalTo(commentsButton.snp_width)
            
        }
        
        line1.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(repostButton.snp_right)
            make.centerY.equalTo(self.snp_centerY)
        }
        
        line2.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentsButton.snp_right)
            make.centerY.equalTo(self.snp_centerY)
        }
        
    }
    
    
    //懒加载
    //转发按钮
    private lazy var repostButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setImage(UIImage(named: "timeline_icon_retweet"), forState: UIControlState.Normal)
        
        button.setTitle("转发", forState: UIControlState.Normal)
        
        button.titleLabel?.font = UIFont.systemFontOfSize(12)
        
        button.setTitleColor(UIColor(white: 180/255.0, alpha: 1), forState: UIControlState.Normal)
        
        return button
    }()
    
    
    //评论按钮
    private lazy var commentsButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setImage(UIImage(named: "timeline_icon_comment"), forState: UIControlState.Normal)
        
        button.setTitle("评论", forState: UIControlState.Normal)
        
        button.titleLabel?.font = UIFont.systemFontOfSize(12)
        
        button.setTitleColor(UIColor(white: 180/255.0, alpha: 1), forState: UIControlState.Normal)
        
        return button
    
    }()
    
    //点赞按钮
    private lazy var goodButton: UIButton = {
        
        let button = UIButton(type: UIButtonType.Custom)
        
        button.setImage(UIImage(named: "timeline_icon_unlike"), forState: UIControlState.Normal)
        
        button.setTitle("赞", forState: UIControlState.Normal)
        
        button.titleLabel?.font = UIFont.systemFontOfSize(12)
        
        button.setTitleColor(UIColor(white: 180/255.0, alpha: 1), forState: UIControlState.Normal)
        
        return button
    }()
    
    //分割线
    //创建一个方法，来返回一个UIImageView
    private func getLine() -> UIImageView {
        
        let iamgeView = UIImageView()
        
        iamgeView.image = UIImage(named: "timeline_card_bottom_line_highlighted")
        
        return iamgeView
    }
    
}
